﻿/****************************************************************************************************************
*                                                                                                               *
* Copyright (C) 2011 5173.com                                                                                   *
* This project may be copied only under the terms of the Apache License 2.0.                                    *
* Please visit the project Home Page http://bqqapicsharp.codeplex.com/ for more detail.                         *
*                                                                                                               *
****************************************************************************************************************/

namespace BQQAPIClient.Core.Protocol
{
    using System.Linq;
    using BQQAPIClient.Core.Business;
    using BQQAPIClient.Core.Utility;

    [NotifyPackage(29, 0)]
    internal class C2SHeartBeatNotifyPackage : IParseOtherData
    {
        private AbstractNotifyPackage abstractNotifyPackage;
        private HeartBeat heartBeat;

        public C2SHeartBeatNotifyPackage(AbstractNotifyPackage package)
        {
            this.abstractNotifyPackage = package;
        }

        public void ParseOtherData()
        {
            heartBeat = new HeartBeat();
            var result = abstractNotifyPackage.otherData.Where(tlv => tlv.t == HeartBeat.TSeqNum).ToList();
            if (result.Count > 0) heartBeat.SeqNum = result.First().v.GetLittleEndianUInt32();

            Logger.Info("C2SHeartBeatNotifyPackage : " + heartBeat.ToString());

            if (BQQAPI.C2SHeartBeatNotifyAction != null)
            {
                BQQAPI.C2SHeartBeatNotifyAction();
            }
        }
    }
}
